package slickSource.models

import java.sql.Timestamp

import io.circe._
import io.circe.generic.auto._
import models.CrawlTables._
import utils.CirceUtils

trait SlcikEncoders extends CirceUtils {

  implicit val CrawlPlanRowObjectEncoder: ObjectEncoder[CrawlPlanRow] = {
    implicit val sqlDateEncoder: Encoder[Timestamp] =
      timestampEncoderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportEncoder.instance
  }

  implicit val CrawlPlanRowDecoder: Decoder[CrawlPlanRow] = {
    implicit val sqlDateEncoder: Decoder[Timestamp] =
      timestampDeocderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportDecoder.instance
  }

  implicit val CrawlUrlsRowObjectEncoder: ObjectEncoder[CrawlUrlsRow] = {
    implicit val TimestampEncoder: Encoder[Timestamp] =
      timestampEncoderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportEncoder.instance
  }

  implicit val CrawlUrlsRowDecoder: Decoder[CrawlUrlsRow] = {
    implicit val TimestampEncoder: Decoder[Timestamp] =
      timestampDeocderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportDecoder.instance
  }

  implicit val CrawlActionRowObjectEncoder: ObjectEncoder[CrawlActionRow] = {
    implicit val TimestampEncoder: Encoder[Timestamp] =
      timestampEncoderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportEncoder.instance
  }

  implicit val CrawlActionRowDecoder: Decoder[CrawlActionRow] = {
    implicit val TimestampEncoder: Decoder[Timestamp] =
      timestampDeocderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportDecoder.instance
  }

  implicit val UpdateCrawlPlanRowObjectEncoder: ObjectEncoder[UpdateCrawlPlanRow] = {
    implicit val TimestampEncoder: Encoder[Timestamp] =
      timestampEncoderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportEncoder.instance
  }

  implicit val UpdateCrawlPlanRowDecoder: Decoder[UpdateCrawlPlanRow] = {
    implicit val TimestampEncoder: Decoder[Timestamp] =
      timestampDeocderFromPattern("yyyy-MM-dd HH:mm:ss")
    exportDecoder.instance
  }

}
